'use strict';

const moment = require('moment');

module.exports = app => {
  const { Sequelize } = app;

  const IntegralIns = app.model.define('IntegralIns', {
    id: {
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      type: Sequelize.INTEGER
    },
    userId: {
      type: Sequelize.INTEGER,
      allowNull: false,
      onDelete: "CASCADE",
      onUpdate: "CASCADE",
      references: {
        model: 'Users',
        key: 'id'
      }
    },
    total: {
      allowNull: false,
      type: Sequelize.INTEGER,
      comment: '总和'
    },
    number: {
      allowNull: false,
      type: Sequelize.INTEGER,
      comment: '收入'
    },
    type: {
      allowNull: false,
      type: Sequelize.INTEGER(1),
      comment: '1：收获、2：每日分享'
    },
    createdAt: {
      allowNull: false,
      type: Sequelize.DATE(3),
      get() { return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm') },
    },
    updatedAt: {
      allowNull: false,
      type: Sequelize.DATE(3),
      get() { return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm') },
    },
  }, {
    timestamps: false,
    charset: 'utf8mb4',
    collate: 'utf8mb4_general_ci',
    comment: '商品图片表'
  });

  return IntegralIns;

};